package com.chalmers.foa.gamehandlers.impl;

import android.graphics.Point;

public class PhysicsHandler {

	private static PhysicsHandler physicsHandler;

	private int gravity;
	private int oldGravity;

	public static PhysicsHandler getInstance() {
		if (physicsHandler == null)
			physicsHandler = new PhysicsHandler();
		return physicsHandler;
	}

	public PhysicsHandler() {
		gravity = 3;
		oldGravity = gravity;
	}

	public void applyGravitationToOffset(Point offset) {
		offset.y += getGravity();
	}

	public void applyGravitationToOffset(Point offset, boolean reversed) {
		if (!reversed)
			offset.y += getGravity();
		else
			offset.y -= getGravity();
	}

	public void applyGravitationToOffset(Point offset, int force) {
		if (getGravity() >= 0)
			offset.y += force;
		else
			offset.y -= force;
	}

	public void applyTilting(Point offset) {
		offset.x = -(int) (InputHandler.getInstance().getAccelerometerValues()[1] / (7) * InputHandler
				.getInstance().getSpeedMultiplier());
	}

	public void reverseGravity() {
		setGravity(-gravity);
	}

	public void setGravity(int gravity) {
		oldGravity = this.gravity;
		this.gravity = gravity;
	}

	public int getGravity() {
		return (int) (gravity * InputHandler.getInstance().getSpeedMultiplier());
	}

	public int getOldGravity() {
		return oldGravity;
	}

}
